package
{
	import flash.events.MouseEvent;
	import flash.geom.Point;

	public class GameInputManager
	{
		private var m_game:Game;
		private var m_gameModes:Vector.<IGameMode>;
		
		private var m_dragHelper:MouseDragHelper = new MouseDragHelper();
		private var m_mouseDown:Boolean;
		private var m_mouseDownPosition:Point = new Point();
		
		public function GameInputManager(game:Game, gameModes:Vector.<IGameMode>)
		{
			m_game = game;
			m_gameModes = gameModes;

			m_game.display.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
			m_game.display.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
			m_game.display.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);	
		}
		
		public function onMouseMove(me:MouseEvent):void{
			m_dragHelper.onMouseMove(me);
			if(m_dragHelper.isDragging()){
				m_game.onMouseDrag(m_dragHelper.dragVector);
			} else {
				m_gameModes[0].onMouseMove(me);	
			}
		}		
		
		public function onMouseDown(me:MouseEvent):void{
			m_dragHelper.onMouseDown(me);
			if(!m_dragHelper.isDragging()){
				m_gameModes[0].onMouseDown(me);
			}
		}
		
		public function onMouseUp(me:MouseEvent):void{
			m_dragHelper.onMouseUp(me);
			if(!m_dragHelper.isDragging()){
				m_gameModes[0].onMouseUp(me);
			}
		}
				
	}
}